﻿using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Mail;
using System.Text;

namespace Commons
{
    public class MailUtils
    {
        public static async System.Threading.Tasks.Task SendEmailAsync(string fromAddr, string psw , string toAddr,string subject, string body)
        {
      
            MailMessage myMail = new MailMessage();

            myMail.From = new MailAddress(fromAddr);
            myMail.To.Add(new MailAddress(toAddr));

            myMail.Subject = subject;
            myMail.SubjectEncoding = Encoding.UTF8;

            myMail.Body = body;
            myMail.BodyEncoding = Encoding.UTF8;
            myMail.IsBodyHtml = true;

            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.qq.com";
            smtp.Credentials = new NetworkCredential(fromAddr, psw);
            await smtp.SendMailAsync(myMail);
        }
    }
}
